package com.meixiang.adapter.bank;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.BankBean;
import com.meixiang.recyclerview.OnItemClick;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：zys  银行卡列表适配器
 */
public class ChooseBankCardAdapter extends RecyclerView.Adapter<ChooseBankCardAdapter.ContentViewHolder> {

    private List<BankBean> mDatas;

    public void setData(List<BankBean> datas) {
        this.mDatas = datas;
        notifyDataSetChanged();
    }

    private OnItemClick onItemClickListener;

    public void setOnItemClickListener(OnItemClick onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public ContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_choose_bank_card, parent, false);
        ContentViewHolder viewHolder = new ContentViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ContentViewHolder holder, int position) {
        BankBean bean = mDatas.get(position);
        if (bean != null) {
            holder.tvBanName.setText(bean.getBankName());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(v, holder.getLayoutPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    static class ContentViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_bank_card)
        ImageView ivBankCard;
        @Bind(R.id.tv_ban_name)
        TextView tvBanName;

        public ContentViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}